package com.luo.ai.mcp.server.config;

import io.modelcontextprotocol.server.McpServerFeatures;
import io.modelcontextprotocol.spec.McpSchema;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 提示配置
 *
 * @author luohq
 * @date 2025-04-27 13:14
 */
@Configuration
public class PromptsConfig {

    /**
     * 注册提示
     *
     * @return 提示说明
     */
    @Bean
    public List<McpServerFeatures.SyncPromptSpecification> myPrompts() {
        //提示模版描述
        McpSchema.Prompt prompt = new McpSchema.Prompt(
                "greeting",
                "A friendly greeting prompt",
                //提示模版参数(name, description, required)
                List.of(new McpSchema.PromptArgument("name", "The name to greet", true)));

        //具体提示模版实现（对应prompts/get接口）
        McpServerFeatures.SyncPromptSpecification promptSpecification = new McpServerFeatures.SyncPromptSpecification(
                prompt,
                (exchange, getPromptRequest) -> {
                    //获取提示模版参数
                    String nameArgument = (String) getPromptRequest.arguments().get("name");
                    if (nameArgument == null) {
                        nameArgument = "friend";
                    }
                    //生成提示内容
                    McpSchema.PromptMessage userMessage = new McpSchema.PromptMessage(
                            McpSchema.Role.USER,
                            new McpSchema.TextContent("Hello " + nameArgument + "! How can I assist you today?")
                    );
                    return new McpSchema.GetPromptResult("A personalized greeting message", List.of(userMessage));
                });

        //提示模版列表（对应prompts/list接口）
        return List.of(promptSpecification);
    }
}
